import { exec } from 'child_process';
import { existsSync } from 'fs';
import { copyFile, mkdir } from 'fs/promises';
import { join } from 'path';
import { promisify } from 'util';

const promiseExec = promisify(exec);

(async () => {
    await promiseExec('npm i');

    const psdDeclareDirPath = join(__dirname, '..', 'node_modules', '@types', 'psd');
    if (!existsSync(psdDeclareDirPath))
        await mkdir(psdDeclareDirPath);

    await copyFile(
        join(__dirname, '..', '@types', 'psd.d.ts'),
        join(psdDeclareDirPath, 'index.d.ts')
    );

    await promiseExec('tsc -b build.tsconfig.json');
})();